<template>
    <div class="resume_list">
        <div v-for="resume in result.list" :key="resume.resume_management_id">
            <div>
                <el-card style="width:800px;margin-left:150px;margin-top:50px;background-color:rgba(191, 118, 110, 0.184)">
                    <h2>简历名称:{{ resume.resume_name }}</h2>
                    <el-tag size="medium">创建时间:{{ format(resume.create_time).format }}</el-tag><br>
                    <el-tag size="medium">更新时间:{{ format(resume.update_time).format }}</el-tag><br>
                    <el-button @click="detail(resume.resume_management_id)" type="info">查看简历</el-button>
                    <el-button type="danger"
                        @click="deleteResume(resume.resume_management_id, resume.resume_name)">删除简历</el-button>
                </el-card>
            </div>
        </div>
        <div style="margin-top:10px;margin-left:-250px;">
            <div class="block">
                <el-pagination :current-page="currentPage" :page-size="pageSize" layout="total,  prev, pager, next, jumper"
                    :total="total" @current-change="handleCurrentChange">
                </el-pagination>
            </div>
        </div>
        <el-button @click="addNewResume" type="primary" style="margin-left:-300px;margin-top:50px;">创建新的简历</el-button>
    </div>
</template>
<script>
import axios from 'axios';
import dateTime from '@/utils/date_time';
export default {
    data() {
        return {
            result: [],
            pageSize: 2,
            pagerCount: 0,
            total: 0,
            currentPage: 1,
        }
    },
    methods: {
        handleCurrentChange(val) {
            if (!window.localStorage.getItem("token")) {
                this.$router.push({ path: '/login' }, () => { }, () => { });
                return;
            }
            let that = this;
            axios({
                method: 'get',
                url: 'http://127.0.0.1:5000/api/resume_management/get_list',
                params: {
                    user: window.localStorage.getItem("user_id"),
                    page: val,
                    size: that.pageSize
                },
                headers: {
                    'X-Auth-Token': window.localStorage.getItem("token")
                },
            })
                .then(function (response) {
                    console.log(response.data);
                    that.result = response.data.result;
                    that.total = Number.parseInt(response.data.result.count);
                    that.pagerCount = that.total % that.pageSize;
                })
                .catch(function (error) {
                    console.log(error);
                })
                .then(function () {
                    // 总是会执行
                })
        },
        detail(id) {
            this.$router.push({ name: 'resume_detail', params: { resume_management_id: id } }, () => { }, () => { });
        },
        format(create_time) {
            return dateTime.dateTime(create_time)
        },
        addNewResume() {
            this.$router.push({ name: 'resume_add' }, () => { }, () => { });
        },
        deleteResume(id, name) {
            if (!window.confirm("是否删除简历名称为:[" + name + "]的简历")) {
                return;
            }
            axios({
                method: 'post',
                url: 'http://127.0.0.1:5000/api/resume_management/del',
                params: {
                    resume_management_id: id,
                },
                headers: {
                    'X-Auth-Token': window.localStorage.getItem("token")
                },
            })
                .then(function (response) {
                    console.log(response.data);
                    window.location.reload();
                })
                .catch(function (error) {
                    console.log(error);
                })
                .then(function () {
                    // 总是会执行
                })
        }
    },
    created: function () {
        if (!window.localStorage.getItem("token")) {
            this.$router.push({ path: '/login' }, () => { }, () => { });
            return;
        }
        let that = this;
        axios({
            method: 'get',
            url: 'http://127.0.0.1:5000/api/resume_management/get_list',
            params: {
                user: window.localStorage.getItem("user_id"),
                page: 1,
                size: that.pageSize
            },
            headers: {
                'X-Auth-Token': window.localStorage.getItem("token")
            },
        })
            .then(function (response) {
                console.log(response.data);
                that.result = response.data.result;
                that.total = Number.parseInt(response.data.result.count);
                that.pagerCount = that.total % that.pageSize;
            })
            .catch(function (error) {
                console.log(error);
            })
            .then(function () {
                // 总是会执行
            })
    }
}
</script>
<style scoped>
.resume_list {
    margin-top: -400px;
    margin-left: 500px;

}
</style>